﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using IOBusiness;
using IOEntity;
namespace Indochinaodyssey.Admin
{
    public partial class Infomation : System.Web.UI.Page
    {
        clsBSInfomation obj = new clsBSInfomation();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                if (Request.QueryString["action"] != null)
                {
                    if (this.pnInfo.Visible == false)
                    {
                        if (Request.QueryString["action"].ToString().Equals("new"))
                        {
                            this.pnInfo.Visible = true;
                            this.txtTieuDe.Text = "";
                            this.txtNoiDung.Value = "";
                            this.ddlQuocGia.Enabled = true;
                            this.ddlTheLoai.Enabled = true;
                        }
                        else
                        {
                            if (Request.QueryString["action"].ToString().Equals("edit"))
                            {
                                if (Request.QueryString["ID"] != null)
                                {
                                    this.pnInfo.Visible = true;
                                    int id = Convert.ToInt32(Request.QueryString["ID"]);
                                    clsInfomation about = new clsInfomation();
                                    about = obj.GetById(id);
                                    this.txtTieuDe.Text = about.TieuDe;
                                    this.txtNoiDung.Value = about.NoiDung;
                                    this.ddlQuocGia.Enabled = false;
                                    this.ddlTheLoai.Enabled = false;
                                }
                            }
                        }
                    }
                }
                else
                {
                    this.pnInfo.Visible = false;
                }

            }
            catch (Exception)
            {

                throw;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["action"] != null)
            {
                clsInfomation about = new clsInfomation();
                about.TieuDe = this.txtTieuDe.Text;
                about.NoiDung = this.txtNoiDung.Value;
                about.TheLoai.Id = Convert.ToInt32(this.ddlTheLoai.SelectedValue);
                if (Request.QueryString["action"].ToString().Equals("new"))
                {
                    obj.Insert(about);
                    this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Thêm mới thành công')</script>");
                }
                else
                {
                    if (Request.QueryString["action"].ToString().Equals("edit"))
                    {
                        if (Request.QueryString["ID"] != null)
                        {
                            clsBSInfomation bsi = new clsBSInfomation();
                            clsInfomation ifo = new clsInfomation();
                            int id = Convert.ToInt32(Request.QueryString["ID"]);
                            ifo = bsi.GetById(id);
                            about.TheLoai.Id = ifo.TheLoai.Id;
                            about.Id = id;
                            obj.Update(about);
                            this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Cập nhật thành công')</script>");
                        }
                    }
                }
            }
            this.odsInfomation.DataBind();
            this.GridView1.DataBind();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Xoa"))
            {
                obj.Delete(Convert.ToInt32(e.CommandArgument));
                this.GridView1.DataBind();
            }

        }

        protected void ddlTheLoai_Load(object sender, EventArgs e)
        {

        }

        protected void ddlTheLoai_DataBinding(object sender, EventArgs e)
        {
        }
    }
}